from building import * 
import rtconfig

# get current dir path
cwd  = GetCurrentDir()
objs = []

LOCAL_CCFLAGS = ''

if rtconfig.CROSS_TOOL == 'gcc':
    LOCAL_CCFLAGS += ' -std=c99'
elif rtconfig.CROSS_TOOL == 'keil':
    LOCAL_CCFLAGS += ' --c99 --gnu -g -W'

# add lvgl source & include
lvgl_inc  = []
lvgl_src  = []

lvgl_inc += [cwd]
lvgl_inc += [cwd + "/lvgl"]
lvgl_inc += [cwd + "/lvgl/src/lv_core"]
lvgl_inc += [cwd + "/lvgl/src/lv_draw"]
lvgl_inc += [cwd + "/lvgl/src/lv_font"]
lvgl_inc += [cwd + "/lvgl/src/lv_hal"]
lvgl_inc += [cwd + "/lvgl/src/lv_misc"]
lvgl_inc += [cwd + "/lvgl/src/lv_objx"]
lvgl_inc += [cwd + "/lvgl/src/lv_themes"]

lvgl_src += Glob('./lvgl/src/lv_core/*.c')
lvgl_src += Glob('./lvgl/src/lv_draw/*.c')
lvgl_src += Glob('./lvgl/src/lv_font/*.c')
lvgl_src += Glob('./lvgl/src/lv_hal/*.c')
lvgl_src += Glob('./lvgl/src/lv_misc/*.c')
lvgl_src += Glob('./lvgl/src/lv_objx/*.c')
lvgl_src += Glob('./lvgl/src/lv_themes/*.c')

# add rtthread support source
lvgl_src += Glob('./*.c')

lvgl_objs = DefineGroup('lvgl', src = lvgl_src, depend = ['PKG_USING_EZLVGL'], CPPPATH = lvgl_inc, LOCAL_CCFLAGS = LOCAL_CCFLAGS)

# add lv_axamples apps tests tutorial
if GetDepend('PKG_USING_LVGL_EXAMPLE'):
    local_options = LocalOptions(cwd + '/lv_ex_conf.h')

    lv_examples_src = []
    lv_examples_inc = [cwd + '/lv_examples']
    
    lv_apps_src 	= []
    lv_apps_inc 	= []
    lv_tests_src 	= []
    lv_tests_inc 	= []
    lv_tutorial_src = []
    lv_tutorial_inc = []
    
    if GetLocalDepend(local_options,'LV_USE_BENCHMARK') != False:
        lv_apps_src += Glob('./lv_examples/lv_apps/benchmark/*.c')
        lv_apps_inc += [cwd + "/lv_examples/lv_apps/benchmark"]
        
    if GetLocalDepend(local_options,'LV_USE_DEMO') != False:
        lv_apps_src += Glob('./lv_examples/lv_apps/demo/*.c')
        lv_apps_inc += [cwd + "/lv_examples/lv_apps/demo"]
        
    if GetLocalDepend(local_options,'LV_USE_SYSMON') != False:
        lv_apps_src += Glob('./lv_examples/lv_apps/sysmon/*.c')
        lv_apps_inc += [cwd + "/lv_examples/lv_apps/sysmon"]
        
    if GetLocalDepend(local_options,'LV_USE_TERMINAL') != False:
        lv_apps_src += Glob('./lv_examples/lv_apps/terminal/*.c')
        lv_apps_inc += [cwd + "/lv_examples/lv_apps/terminal"]
        
    if GetLocalDepend(local_options,'LV_USE_TPCAL') != False:
        lv_apps_src += Glob('./lv_examples/lv_apps/tpcal/*.c')
        lv_apps_inc += [cwd + "/lv_examples/lv_apps/tpcal"]
        
    if GetLocalDepend(local_options,'LV_USE_TESTS') != False:
        lv_tests_inc += [cwd + "/lv_examples/lv_tests"]
        lv_tests_src += Glob('./lv_examples/lv_tests/lv_test_group/*.c')
        lv_tests_src += Glob('./lv_examples/lv_tests/lv_test_misc/*.c')
        lv_tests_src += Glob('./lv_examples/lv_tests/lv_test_obj/*.c')
        lv_tests_src += Glob('./lv_examples/lv_tests/lv_test_objx/*.c')
        lv_tests_src += Glob('./lv_examples/lv_tests/lv_test_stress/*.c')
        lv_tests_src += Glob('./lv_examples/lv_tests/lv_test_theme/*.c')
        
    if GetLocalDepend(local_options,'LV_USE_TUTORIALS') != False:
        lv_tutorial_src += Glob('./lv_examples/lv_tutorial/1_hello_world/*.c')
        lv_tutorial_inc += [cwd + "/lv_examples/lv_tutorial/1_hello_world"]
        lv_tutorial_src += Glob('./lv_examples/lv_tutorial/2_objects/*.c')
        lv_tutorial_inc += [cwd + "/lv_examples/lv_tutorial/2_objects"]
        lv_tutorial_src += Glob('./lv_examples/lv_tutorial/3_styles/*.c')
        lv_tutorial_inc += [cwd + "/lv_examples/lv_tutorial/3_styles"]
        lv_tutorial_src += Glob('./lv_examples/lv_tutorial/4_themes/*.c')
        lv_tutorial_inc += [cwd + "/lv_examples/lv_tutorial/4_themes"]
        lv_tutorial_src += Glob('./lv_examples/lv_tutorial/5_antialiasing/*.c')
        lv_tutorial_inc += [cwd + "/lv_examples/lv_tutorial/5_antialiasing"]
        lv_tutorial_src += Glob('./lv_examples/lv_tutorial/6_images/*.c')
        lv_tutorial_inc += [cwd + "/lv_examples/lv_tutorial/6_images"]
        lv_tutorial_src += Glob('./lv_examples/lv_tutorial/7_fonts/*.c')
        lv_tutorial_inc += [cwd + "/lv_examples/lv_tutorial/7_fonts"]
        lv_tutorial_src += Glob('./lv_examples/lv_tutorial/8_animations/*.c')
        lv_tutorial_inc += [cwd + "/lv_examples/lv_tutorial/8_animations"]
        lv_tutorial_src += Glob('./lv_examples/lv_tutorial/9_responsive/*.c')
        lv_tutorial_inc += [cwd + "/lv_examples/lv_tutorial/9_responsive"]
        lv_tutorial_src += Glob('./lv_examples/lv_tutorial/10_keyboard/*.c')
        lv_tutorial_inc += [cwd + "/lv_examples/lv_tutorial/10_keyboard"]
        
    # collect all source...
    lv_examples_src = lv_apps_src + lv_tests_src + lv_tutorial_src
    lv_examples_inc = lv_apps_inc + lv_tests_inc + lv_tutorial_inc
    lvgl_examples_objs = DefineGroup('lvgl_examples', lv_examples_src, depend = ['PKG_USING_EZLVGL','PKG_USING_LVGL_EXAMPLE'], CPPPATH = lv_examples_inc, LOCAL_CCFLAGS = LOCAL_CCFLAGS)
    ret_objs = lvgl_objs + lvgl_examples_objs
    Return ('ret_objs')
	
Return('lvgl_objs')
